package com.teach.servlets;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * <pre>
 * - Servlet生命周期演示
 * Author : J.L.Zhou
 * E-Mail : 2233875735@qq.com
 * Tel : 151 1104 7708
 * Date : 2021-5-7 15:27:18
 * Version : 1.0
 * Copyright 2021 jlzhou.top Inc. All rights reserved.
 * Warning: this content is only for internal circulation of the company.
 *          It is forbidden to divulge it or use it for other commercial purposes.
 * </pre>
 */
@WebServlet(
		urlPatterns = "/retention.let",
		loadOnStartup = 1
		
		)
public class RetentionServlet  extends HttpServlet {
	
	public RetentionServlet() {
		System.out.println("实例化："+this);
	}
	
	@Override
	public void init() throws ServletException {
		System.out.println("初始化回调init："+this);
	}
	
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();//获取字符输出流
		out.println("<h1>提供服务</h1>"+Thread.currentThread().getName()+"<br/> "+this);
		System.out.println("<h1>提供服务</h1>"+Thread.currentThread().getName()+"<br/> "+this);
		out.flush();
		out.close();
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doGet(req, resp);
	}
	
	@Override
	public void destroy() {
		System.out.println("销毁回调destroy："+this);
	}
}
